#include "Tap.h"



Tap::Tap()
{
	state =TestLogicReset;
	TMS = BitPointer();
}
Tap::Tap(BitPointer tms)
{
	state = TestLogicReset;
	TMS= tms;
}

unsigned char Tap::getState() //gets the current state.
{
	return state;
}
void Tap::run() //do a transition to the next state.
{
	switch(state)
	{
		case TestLogicReset:
			if(TMS.getBit()==1)
				state = TestLogicReset;
			else
				state = RunTestIdle;
			break;
		case RunTestIdle:
			if(TMS.getBit()==1)
				state = SelectDRScan;
			else
				state = RunTestIdle;
			break;
		case SelectDRScan:
			if(TMS.getBit()==1)
				state = SelectIRScan;
			else
				state = CaptureDR;
			break;
		case SelectIRScan:
			if(TMS.getBit()==1)
				state = TestLogicReset;
			else
				state = CaptureIR;
			break;
		case CaptureDR:
			if(TMS.getBit()==1)
				state = Exit1DR;
			else
				state = ShiftDR;
			break;
		case CaptureIR:
			if(TMS.getBit()==1)
				state = Exit1IR;
			else
				state = ShiftIR;
			break;
		case ShiftDR:
			if(TMS.getBit()==1)
				state = Exit1DR;
			else
				state = ShiftDR;
			break;
		case ShiftIR:
			if(TMS.getBit()==1)
				state = Exit1IR;
			else
				state = ShiftIR;
			break;
		case Exit1DR:
			if(TMS.getBit()==1)
				state = UpdateDR;
			else
				state = PauseDR;
			break;
		case Exit1IR:
			if(TMS.getBit()==1)
				state = UpdateIR;
			else
				state = PauseIR;
			break;
		case PauseDR:
			if(TMS.getBit()==1)
				state = Exit2DR;
			else
				state = PauseDR;
			break;
		case PauseIR:
			if(TMS.getBit()==1)
				state = Exit2IR;
			else
				state = PauseIR;
			break;
		case Exit2DR:
			if(TMS.getBit()==1)
				state = UpdateDR;
			else
				state = ShiftDR;
			break;
		case Exit2IR:
			if(TMS.getBit()==1)
				state = UpdateIR;
			else
				state = ShiftIR;
			break;
		case UpdateDR:
			if(TMS.getBit()==1)
				state = SelectDRScan;
			else
				state = RunTestIdle;
			break;
		case UpdateIR:
			if(TMS.getBit()==1)
				state = SelectDRScan;
			else
				state = RunTestIdle;
			break;
		default:	

			state = TestLogicReset;

			break;
	}
}


